package com.huawei.fastengine.fastview.download.emui.widget;

import android.os.SystemProperties;
import android.text.TextUtils;
import com.huawei.fastengine.BuildConfig;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public final class EMUISupportUtil {
    public static final int EMUI_1_0 = 1;
    public static final int EMUI_1_5 = 2;
    public static final int EMUI_1_6 = 3;
    public static final int EMUI_2_0_JB = 4;
    public static final int EMUI_2_0_KK = 5;
    public static final int EMUI_2_3 = 6;
    public static final int EMUI_3_0 = 7;
    public static final int EMUI_3_0_5 = 8;
    public static final int EMUI_3_1 = 8;
    public static final int EMUI_4_0 = 9;
    public static final int EMUI_4_1 = 10;
    public static final int EMUI_5_0 = 11;
    public static final int EMUI_5_1 = 12;
    private static final String TAG = "EMUISupportUtil";
    private static final String UNDERLINE_SYMBOL = "_";
    public static final int UNKNOWN_EMUI = 0;
    private static final Map<Integer, String> emuiVersionMap = new HashMap();
    private static EMUISupportUtil instance;
    private int emuiVersion;
    private String emuiVersionName;

    static {
        emuiVersionMap.put(Integer.valueOf(1), BuildConfig.VERSION_NAME);
        emuiVersionMap.put(Integer.valueOf(2), "1.5");
        emuiVersionMap.put(Integer.valueOf(3), "1.6");
        emuiVersionMap.put(Integer.valueOf(4), "2.0");
        emuiVersionMap.put(Integer.valueOf(5), "2.0");
        emuiVersionMap.put(Integer.valueOf(6), "2.3");
        emuiVersionMap.put(Integer.valueOf(7), "3.0");
        emuiVersionMap.put(Integer.valueOf(8), "3.0.5");
        emuiVersionMap.put(Integer.valueOf(8), "3.1");
        emuiVersionMap.put(Integer.valueOf(9), "4.0");
        emuiVersionMap.put(Integer.valueOf(10), "4.1");
        emuiVersionMap.put(Integer.valueOf(11), "5.0");
        emuiVersionMap.put(Integer.valueOf(12), "5.1");
    }

    private EMUISupportUtil() {
        this.emuiVersion = 0;
        this.emuiVersionName = "";
        this.emuiVersion = getEmuiVersionCode();
        if (this.emuiVersion == 0) {
            this.emuiVersion = getEmuiVerFromBuild();
        }
        this.emuiVersionName = initEmuiVersionName();
    }

    private int getEmuiVerFromBuild() {
        Object emuiVersionName = getEmuiVersionName(SystemProperties.get("ro.build.version.emui", ""));
        if (!TextUtils.isEmpty(emuiVersionName)) {
            for (Entry entry : emuiVersionMap.entrySet()) {
                if (emuiVersionName.startsWith((String) entry.getValue())) {
                    return ((Integer) entry.getKey()).intValue();
                }
            }
        }
        return 0;
    }

    private int getEmuiVersionCode() {
        return SystemProperties.getInt("ro.build.hw_emui_api_level", 0);
    }

    private String getEmuiVersionName(String str) {
        String str2 = "";
        if (TextUtils.isEmpty(str)) {
            return str2;
        }
        String[] split = str.split("_");
        return split.length == 2 ? split[1] : str2;
    }

    public static synchronized EMUISupportUtil getInstance() {
        EMUISupportUtil eMUISupportUtil;
        synchronized (EMUISupportUtil.class) {
            if (instance == null) {
                instance = new EMUISupportUtil();
            }
            eMUISupportUtil = instance;
        }
        return eMUISupportUtil;
    }

    private String initEmuiVersionName() {
        String str = (String) emuiVersionMap.get(Integer.valueOf(this.emuiVersion));
        return str == null ? "" : str;
    }

    public int getEmuiVersion() {
        return this.emuiVersion;
    }

    public String getEmuiVersionName() {
        return this.emuiVersionName;
    }

    public boolean isEMUI3() {
        return this.emuiVersion > 6 && this.emuiVersion < 9;
    }

    public boolean isEMUI4() {
        return this.emuiVersion > 8 && this.emuiVersion < 11;
    }

    public boolean isEMUI4Style() {
        return this.emuiVersion >= 9;
    }

    public boolean isEMUI5() {
        return this.emuiVersion >= 11;
    }
}
